package cn.edu.scau.common.utils;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

import java.util.UUID;

/**
 * @description:
 * @author: yuxiang
 * @create: 2019-12-02 15:54
 **/
public class UUIDUtils {

    public static String getUUID(){
        return UUID.randomUUID().toString().replace("-", "");
    }

    /**
     * 根据用户名生成盐值
     * @param userName
     * @return
     */
    public static ByteSource getSaltByName(String userName) {
        return ByteSource.Util.bytes(userName);
    }

    /**
     * 获取密文
     * @param password 明文密码
     * @param salt 盐值
     * @param hashTime 散列次数
     * @return
     */
    public static String getCredentials(String password, ByteSource salt, int hashTime) {
        return new SimpleHash("MD5",  password, salt, hashTime).toHex();
    }

}
